//
//  DistritosViewController.m
//  Futbol5Final
//
//  Created by Johan Chaves on 4/14/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "DistritosViewController.h"
#import "DistritosCreator.h"
#import "DistritosVO.h"

@implementation DistritosViewController

@synthesize distritos,localesViewController;

- (id) initWithDistritos :(CantonVO*)pcanton:(NSDictionary *) distritosData{
    [distritos dealloc];
    [distritos release];
    
    self = [[[DistritosViewController alloc] initWithNibName:@"DistritosViewController" bundle:nil] autorelease];
    
    DistritosCreator *distritosCreator = [[DistritosCreator alloc]init];
    
    distritos = [distritosCreator createDistritos:pcanton:distritosData];
    
    return self;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [distritos count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"distrito";
    
    DistritosVO *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [distritos objectAtIndex:indexPath.row];
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    }
    
    return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    DistritosVO *distritop = (DistritosVO*)[tableView cellForRowAtIndexPath:indexPath];        
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
	    
        //	        self.detailViewController = [[[com_digitalart_futbol5_mobileDetailViewController alloc] initWithNibName:@"com_digitalart_futbol5_mobileDetailViewController_iPhone" bundle:nil] autorelease];
        
        self.localesViewController = [[LocalesViewController alloc]initWithLocales:distritop:[distritop locales]];
        
	    
        [self.navigationController pushViewController:self.localesViewController animated:YES];
    }
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"Distritos";
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
